package com.spt.springbootzhsx.service.suggest.Get_UserToMovieList_1;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class GetUTM_Reducer  extends Reducer<Text, Text, Text, Text> {
    private Text outK = new Text();
    private Text outV = new Text();

    @Override
    protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        StringBuffer sb = new StringBuffer();

        for (Text value : values) {
            //拼接同一个用户观看的电影id字符串
            sb.append(value.toString() + ",");
        }

        //将字符串最后的‘，’去掉
        sb.setLength(sb.length() - 1);

        outV.set(sb.toString());
        context.write(key, new Text(sb.toString()));
        outV.clear();
    }
}
